package com.rankeiot.core;

import com.rankeiot.core.config.ConfigManager;
import com.rankeiot.core.dict.FixedDictManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
public interface Module extends ApplicationContextAware {
   default void setApplicationContext(ApplicationContext applicationContext) throws BeansException{
      System.out.println("module start:"+name());
      start(applicationContext);
   }
   default boolean enable(){
       return true;
   }
   default void start(ApplicationContext applicationContext){}
    /**
     * 模块名
     * @return
     */
    default String name() {
        return this.getClass().getName();
    }
    /**
     * 注册用户菜单
     * @param menuClass 菜单定义接口
     */
    default void regMenu(Class menuClass) {
        MenuManager.regMenu(menuClass);
    }

    /**
     * 注册会员菜单
     * @param menuClass 菜单定义接口
     */
    default void regMemberMenu(Class menuClass) {
        MenuManager.regMemberMenu(menuClass);
    }

    /**
     * 注册配置项
     * @param configClass
     */
    default void regConfigs(Class<? extends Enum> configClass){
        ConfigManager.register(name(),configClass);
    }

    /**
     * 注册固定的字典项,非固定字典项可以直接在系统中添加
     * @param configClass
     */
    default void regFixedDict(Class<? extends Enum> configClass){
        FixedDictManager.regFixedDict(configClass);
    }
}
